<template>
	<view class="page">
		<view class="title f_48 navy_blue">最新公告</view>
		<notice-list type="1" :list="noticesList" @bind-notice-view="bindNotice"/>
		<load-more :status="loasStatus"></load-more>
	</view>
</template>

<script>
const app = getApp();
import noticeList from '@/components/notice-list/index.vue'; //资讯列表
import loadMore from '@/components/loadmore/index.vue';

import { comPageMixinFun } from '@/static/mixins/comPageCommon.js';
import { commonMixinFun } from '@/static/mixins/common.js';
import API from '@/static/api/index.js';
export default {
	components: {
		noticeList,
		loadMore
	},
	mixins: [commonMixinFun, comPageMixinFun],
	data() {
		return {
			loasStatus:'empty',
			noticesList:[],
			page:1,
			size:10,
			totals:0,
			isRequest:false
		};
	},
	onShow(){
		this.getTNoticeList()
	},
	methods:{
		getTNoticeList(){
			let {page,size,isRequest,noticesList,loasStatus,totals}=this
			if(!isRequest&&(noticesList.length<totals||totals==0)){
				this.isRequest=true
				if(loasStatus!='nomore'){
					loasStatus='loading'
				}
				API.getTNoticeList(page,size).then(({code,data,msg})=>{
					if(code==1){
						app._log(code,data,msg)
						let tempArr = (page==1?[]:noticesList).concat(data.notices);
						if(tempArr.length>0){
							this.totals = data.total
							this.page+=(data.total>=tempArr.length?0:1)
						}
						this.noticesList = tempArr;
						this.loasStatus=tempArr.length==0?'empty':(data.total>=tempArr.length?'nomore':'getmore')
					}else{
						this.loasStatus='empty'
						this.showToast(msg||'请求失败')
					}
				this.isRequest=false
				}).catch(err=>{
				this.isRequest=false
				this.loasStatus='error'
					this.showToast(err.msg||'加载失败')
				})
			}
		},
		// 点击咨询
		bindNotice(index){
			this.pageTo('/pages/teacher/announcement_detail/index',{id:this.noticesList[index].notice_id})
			app._log(index)
		}
	},
	onReachBottom() {
		this.getTNoticeList()
	}
};
</script>

<style lang="scss" scoped>
.page{
	background-color: #fff;
	
}
.page > .title {
	width: 750rpx;
	line-height: 98rpx;
	padding-left: 48rpx;
}
	.com_learning_scroll_view{
		/* #ifndef APP-PLUS-NVUE */
		position: -webkit-sticky;
		/* #endif */
		position: sticky;
		// top: var(--window-top);
		z-index: 99;
		top: 0;
	}
</style>
